﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Windows.Forms.DataVisualization.Charting;

namespace MarketFunds
{
    public partial class frmIndustryDetail : Form
    {
        public string m_strSCode = string.Empty;
        public frmIndustryDetail()
        {
            InitializeComponent();
        }

        private void frmIndustryDetail_Load(object sender, EventArgs e)
        {
            string strSql = string.Format("select top 50 * from industryzb where zb='{0}' order by id desc", m_strSCode);
            OleDbCommand cmd = new OleDbCommand(strSql, StockExcel.CommonUtil.dbconn);
            OleDbDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                DateTime dt = (DateTime)reader["hddate"];
                ListViewItem itm = lvwHistory.Items.Add(dt.ToShortDateString());
                double dValue = (double)reader["TotalHYFunds"];
                itm.SubItems.Add(dValue.ToString("###,###.##"));
            }
            reader.Close();
            cmd.Dispose();

            string strText = string.Empty;
            strText = "1日增仓 : " + StockExcel.CommonUtil.GetIndustryZBDaysFunds(m_strSCode, 1).ToString("###,###.##");
            txtInfo.AppendText(strText + "\r\n");
            strText = "3日增仓 : " + StockExcel.CommonUtil.GetIndustryZBDaysFunds(m_strSCode, 3).ToString("###,###.##");
            txtInfo.AppendText(strText + "\r\n");
            strText = "5日增仓 : " + StockExcel.CommonUtil.GetIndustryZBDaysFunds(m_strSCode, 5).ToString("###,###.##");
            txtInfo.AppendText(strText + "\r\n");
            strText = "10日增仓 : " + StockExcel.CommonUtil.GetIndustryZBDaysFunds(m_strSCode, 10).ToString("###,###.##");
            txtInfo.AppendText(strText + "\r\n");
            strText = "20日增仓 : " + StockExcel.CommonUtil.GetIndustryZBDaysFunds(m_strSCode, 20).ToString("###,###.##");
            txtInfo.AppendText(strText + "\r\n");
            ///下方显示图表
            chartIndustry.ChartAreas[0].AxisX.MajorGrid.LineDashStyle = ChartDashStyle.NotSet; //设置网格类型为虚线
            chartIndustry.ChartAreas[0].AxisY.MajorGrid.LineDashStyle = ChartDashStyle.Dash; //设置网格类型为虚线

            chartIndustry.Series[0].ChartType = SeriesChartType.Line;
            chartIndustry.Series[0].BorderColor = Color.Red;
            chartIndustry.Series[0].LegendText = "板块净流入(亿)";
            chartIndustry.Series[0].IsValueShownAsLabel = true;
            string.Format("select top 50 * from industryzb where zb='{0}' order by id desc", m_strSCode);
            DataSet ds = new DataSet();
            OleDbDataAdapter da = new OleDbDataAdapter(strSql, StockExcel.CommonUtil.dbconn);
            da.Fill(ds, "ds");

            int nRowsCount = ds.Tables[0].Rows.Count;
            if (nRowsCount <= 0)
            {
                return;
            }
            
            for (int i = ds.Tables[0].Rows.Count -1; i>=0; i--)
            {
                DateTime dt = (DateTime)ds.Tables[0].Rows[i]["hddate"];
                double dZL = (double)ds.Tables[0].Rows[i]["TotalHYFunds"] / 100000000;  //亿，除以亿;

                chartIndustry.Series[0].Points.AddXY(dt, dZL.ToString("###,###.##"));
                
            }
            ds.Dispose();
            da.Dispose();
        }
    }
}
